<?php
class HELLO
{
    // 参数描述
    /*{{{*/
    /*
       +----------------------------------------------------------------+
       |输入                                                            |
       +--------------------------------------------+-------------------+
       |参数                                        |描述               |
       +--------------------------------------------+-------------------+
       |                                            |                   |
       +--------------------------------------------+-------------------+

       +----------------------------------------------------------------+
       |输出                                                            |
       +--------------------------------------------+-------------------+
       |参数                                        |描述               |
       +--------------------------------------------+-------------------+
       |'errcode'=>SOAR_ERR::OK                     |成功               |
       +--------------------------------------------+-------------------+
       |'errcode'=>                                 |                   |
       +--------------------------------------------+-------------------+
     */
    /*}}}*/

    private $resource=null;

    public function __construct($resource)
    {/*{{{*/
        $this->resource=$resource;
    }/*}}}*/

    public function call($request)
    {/*{{{*/
        $paras=self::check_para($request);
        if($paras === false)
            return array('errcode'=>SOAR_ERR::PARA);
        if(isset($paras['errcode']))
            return array('errcode'=>$paras['errcode']);

        $response=array('errcode'=>SOAR_ERR::OK,
                'msg'=>$paras['msg'],
                'size'=>strlen($paras['msg']));

        return $response;
    }/*}}}*/

    private function check_para($request)
    {/*{{{*/
        $paras=array();

        if(!isset($request['msg']))
        {
            $paras['msg']='';
        }
        else
        {
            $msg=trim($request['msg']);
            if(strlen($msg) > Sock::MSG_MAX_SIZE/2)
            {
                Errlog::add("%s: msg(%d)(%s) invalid",
                        __METHOD__, strlen($request['msg']),
                            substr($request['msg'], 0, 99));
                return false;
            }
            $paras['msg']=$msg;
        }

        return $paras;
    }/*}}}*/
}
?>
